package danny.hoi.service.cargo.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import danny.hoi.dao.export.cargo.ExportDao;
import danny.hoi.dao.export.cargo.ExportProductDao;
import danny.hoi.domain.export.cargo.Export;
import danny.hoi.domain.export.cargo.ExportExample;
import danny.hoi.domain.export.cargo.ExportProduct;
import danny.hoi.domain.export.cargo.ExportProductExample;
import danny.hoi.service.cargo.ExportProductService;
import danny.hoi.service.cargo.ExportService;
import danny.hoi.utils.UuidUtil;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class ExportProductServiceImpl implements ExportProductService {
    @Autowired
    private ExportProductDao exportProductDao;

    @Override
    public List<ExportProduct> findAll(ExportProductExample example) {
        return exportProductDao.selectByExample(example);
    }

    @Override
    public PageInfo<ExportProduct> findByPages(ExportProductExample example, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<ExportProduct> exportProducts = exportProductDao.selectByExample(example);

        return new PageInfo<>(exportProducts);
    }

    @Override
    public ExportProduct findById(String id) {
        return exportProductDao.selectByPrimaryKey(id);
    }

    @Override
    public void save(ExportProduct exportProduct) {
        exportProduct.setId(UuidUtil.getUuid());

        exportProductDao.insertSelective(exportProduct);
    }

    @Override
    public void update(ExportProduct exportProduct) {
        exportProductDao.updateByPrimaryKeySelective(exportProduct);
    }

    @Override
    public void delete(String id) {
        exportProductDao.deleteByPrimaryKey(id);
    }
}
